from rest_framework.views import APIView
from rest_framework.response import Response
from game.models.player.player import Player
from rest_framework.permissions import IsAuthenticated

class InfoView(APIView):
    permission_classes = ([IsAuthenticated])

    def get(self, request):
        user = request.user
        player = Player.objects.get(user=user)
        return Response({
            'result': 'success',
            'username': user.username,
            'photo': player.photo,
        })

# from django.http import JsonResponse
# from game.models.player.player import Player
#
#
# def getinfo_web(request):
#     user = request.user
#     if not user.is_authenticated:
#         return JsonResponse({
#             "result": "未登录"
#         })
#     else:
#         player = Player.objects.get(user=user)
#         return JsonResponse({
#             "result": "success",
#             "username": player.user.username,
#             "photo": player.photo,
#         })
#
#
# def getinfo_acapp(request):
#     # user = request.user
#     # player = Player.objects.get(user=user)
#     player = Player.objects.all()[0]
#     return JsonResponse({
#         "result": "success",
#         "username": player.user.username,
#         "photo": player.photo,
#     })
#
#
# def getinfo(request):
#     platform = request.GET.get('platform')
#     if platform == 'ACAPP':
#         return getinfo_acapp(request)
#     elif platform == "WEB":
#         return getinfo_web(request)